<?php
namespace Orm\Player;

use Base\Exception\RmException;
class PlayerClass extends \Base\BaseOrmObject{
    protected   $id,
				$player_name = '', // 国家球队名称
                $icon_url = '', //国家图标
				$description = '', // 简单介绍
				$play_times = 0, // 参与比赛总场数
				$score = 0, // 总进球数
				$win_times = 0, // 胜利场数
				$lose_times = 0, // 失败场数
				$ranking = 0, // 实时排名
				$is_del = 0,
				$insert_time = '',
				$update_time = '';

    function __init($data)
    {
        parent::__init($data);
        $this->dformat($data);
    }

    private function dformat()
    {
    }

    public function loadById($id = 0)
    {
        $model = new \Orm\Player\PlayerModel();
        $data = $model->loadById($id);
        self::__init($data);
    }

    public function insert()
    {
        $this->checkNecessaryParam();
        $data = array(
            'player_name' => $this->player_name,
            'icon_url' => $this->icon_url,
			'description' => $this->description,
			'play_times' => $this->play_times,
			'score' => $this->score,
			'win_times' => $this->win_times,
			'lose_times' => $this->lose_times,
			'ranking' => $this->ranking,
        );

        $model = new \Orm\Player\PlayerModel();
        $model->insert($data);
        $this->id = $model->getLastId();
    }

    public function update()
    {
        $this->checkNecessaryParam();
        $data = array(
            'player_name' => $this->player_name,
            'icon_url' => $this->icon_url,
			'description' => $this->description,
			'play_times' => $this->play_times,
			'score' => $this->score,
			'win_times' => $this->win_times,
			'lose_times' => $this->lose_times,
			'ranking' => $this->ranking,
        );

        $model = new \Orm\Player\PlayerModel();
        $is_update = $model->update($data, "`id` = {$this->id}");
        return $is_update;
    }

    public function delete($id)
    {
        $data = array('is_del'=>1);
        $model = new \Orm\Player\PlayerModel();
        $model->update($data, "`id` = {$id}");
    }

    private function checkNecessaryParam()
    {
    }
}